#pragma once
#include "EXHeaderCtrl.h"
#include "EXListCtrlResSet.h"
// CEXListCtrl
class CEXScrollBar;

class AFX_EXT_CLASS CEXListCtrl : public CListCtrl
{
	DECLARE_DYNAMIC(CEXListCtrl)

	typedef struct tagSORT_INFO
	{
		int nColumn;
		CListCtrl * plist;
		BOOL bAscend;
	} SORT_INFO;

	typedef struct tagCOLUMN_DATA
	{
		int nIndex;
		int nWidth;
		BOOL bVislble;
	} COLUMN_DATA;

public:
	CEXListCtrl();
	virtual ~CEXListCtrl();

	void SetScrolls(CEXScrollBar * pVScroll, CEXScrollBar * pHScroll);
	void SetFont(CFont* pFont, BOOL bRedraw = TRUE);
  void SetListCtrlName(CString strName);
	int FindIndex(int nItem);
	void SubclassHeaderCtrl();
	void UseCustomHeader(BOOL bUse) { m_bUseCustomHeader = bUse; }
	void SetHeaderBitmap(UINT nID);

	int InsertColumn(int nCol, const LVCOLUMN* pColumn);
	int InsertColumn(int nCol, LPCTSTR lpszColumnHeading,int nFormat=LVCFMT_LEFT, 
                  int nWidth = -1, int nSubItem = -1);

	int InsertItem(const LVITEM* pItem);
	int InsertItem(int nItem, LPCTSTR lpszItem);
	int InsertItem(int nItem, LPCTSTR lpszItem, int nImage);

	BOOL SetItem(const LVITEM* pItem);
	BOOL SetItem(int nItem, int nSubItem, UINT nMask, LPCTSTR lpszItem,
		int nImage, UINT nState, UINT nStateMask, LPARAM lParam);
	BOOL SetItem(int nItem, int nSubItem, UINT nMask, LPCTSTR lpszItem,
		int nImage, UINT nState, UINT nStateMask, LPARAM lParam, int nIndent);

	BOOL GetColumn(int nCol, LVCOLUMN* pColumn) const;
	BOOL SetColumn(int nCol, const LVCOLUMN* pColumn);

	int GetColumnWidth(int nCol) const;
	BOOL SetColumnWidth(int nCol, int cx);

	CString GetItemText(int nItem, int nSubItem) const;
	int GetItemText(__in int nItem, __in int nSubItem, 
                  __out_ecount_part_z(nLen, return + 1) LPTSTR lpszText,
                  __in int nLen) const;

	BOOL SetItemText(int nItem, int nSubItem, LPCTSTR lpszText);

	BOOL SetColumnOrderArray(int iCount, LPINT piArray);
	BOOL GetColumnOrderArray(LPINT piArray, int iCount = -1);

	BOOL GetSubItemRect(int iItem, int iSubItem, int nArea, CRect& ref);

	BOOL DeleteColumn(int nCol);
	void SetErase(BOOL bErase) { m_bErase = bErase; }

	void Sort();

	void SetHeaderColor(COLORREF crHeader);
	void SetListColor(COLORREF crEven, COLORREF crOdd);

	void LockHeader();
	void UnlockHeader();

	void GetSortColumn(CString & strColumn, BOOL & bAscend);

  //ysy
  void SetResSet(CEXBaseResSet* pResSet);
  CEXListCtrlResSet* m_pListCtrlResSet;

protected:
	void Sort(int nColumn, BOOL bAscend);
	void SetSortIcon(int nIndex);
	static int CALLBACK SortList( LPARAM lItemIndex1_i, LPARAM lItemIndex2_i, 
                              LPARAM lCustomParam_i );

	void DrawText(int nItem, int nSubItem, CDC *pDC, COLORREF crText, 
                COLORREF crBkgnd, CRect& rect);
	void GetDrawColors(int nItem, int nSubItem, COLORREF& colorText, 
                    COLORREF& colorBkgnd);

protected:
	CEXScrollBar * m_pVScroll;
	CEXScrollBar * m_pHScroll;

	CEXHeaderCtrl m_HeaderCtrl;

	CString m_strName;

//	CFont m_ftTahoma11;
	CImageList m_imglstArrow;
	int m_nUpArrow;
	int m_nDownArrow;
	CBitmap m_bmpUpArrow;
	CBitmap m_bmpDownArrow;

	CArray < COLUMN_DATA, COLUMN_DATA > m_arrHeaderItem;
	BOOL m_bAscend;
	DWORD m_nSortColumn;
	COLORREF m_oddCol;
	COLORREF m_evenCol;

	CRect m_rcPrev;
	BOOL m_bUseCustomHeader;

	BOOL m_bErase;
	BOOL m_bHeaderLock;

protected:
	DECLARE_MESSAGE_MAP()
	virtual void PreSubclassWindow();
	virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
public:
	afx_msg void OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS* lpncsp);
	afx_msg void OnSize(UINT nType, int cx, int cy);
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	afx_msg void OnDestroy();
	afx_msg void OnLvnColumnclick(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg void OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg void OnHdnTrack(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg BOOL OnEraseBkgnd(CDC* pDC);
	afx_msg LRESULT OnCustomsizeHeader(WPARAM, LPARAM);
};


